/**
 * 
 * @Project HRL Simulation
 * @Date 20.06.2011
 * @Author Aebi Pascal, Kocher Marc, Sriranjan George
 * @School BFH-TI Biel, Projekt 1
 *
 */

package gui.views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

import gui.Model;


public class ViewerCardPanel  extends JPanel {

	private int width = 800;
	private int height = 830;
	private Model model;
	private JPanel jpSimulationPanel;
	private JButton jbReset;
	private JButton jbSlowDown;
	private JButton jbPlay;
	private JButton jbSpeedUp;
	private JButton jbStatistics;
	private JProgressBar jpbSimulationProgress;

	
	/**
	 * Creates the viewer card panel
	 * 
	 * @param model The model
	 */
	public ViewerCardPanel(Model model) {
		this.model =  model;
		
		this.setPreferredSize(new Dimension(this.width, this.height));
		
		this.createSimulationPanel();
		this.createSimulationProgressPanel();
		this.createButtonPanel();
		
		this.init();
	}
	
	
	/**
	 * Creates the simulation panel
	 */
	private void createSimulationPanel(){
		// Create viewer simulation panel
		this.jpSimulationPanel = new JPanel(new BorderLayout());
		this.jpSimulationPanel.setPreferredSize(new Dimension(this.width, 690));
		this.jpSimulationPanel.setBackground(Color.black);
		this.add(BorderLayout.NORTH, this.jpSimulationPanel);
	}
	
	
	/**
	 * Creates the simulation progress bar panel
	 */
	private void createSimulationProgressPanel(){
		// Create viewer control panel
		JPanel jpSimulationProgressPanel  = new JPanel();
		jpSimulationProgressPanel.setPreferredSize(new Dimension(this.width, 30));
		this.add(BorderLayout.CENTER, jpSimulationProgressPanel);
		
		// Progress slider
		this.jpbSimulationProgress = new JProgressBar(0, 100);
		this.jpbSimulationProgress.setPreferredSize(new Dimension(this.width-40, 25));
		this.jpbSimulationProgress.setStringPainted( true );
		jpSimulationProgressPanel.add(this.jpbSimulationProgress);
	}
	
	
	/**
	 * Creates the button panel
	 */
	private void createButtonPanel(){
		// Create control buttons panel
		JPanel jpViewerControlButtons  = new JPanel();
		jpViewerControlButtons.setPreferredSize(new Dimension(this.width, 35));
		this.add(BorderLayout.SOUTH, jpViewerControlButtons);
		
		
		// Create start button
		this.jbReset = new JButton("Reset");
		this.jbReset.setPreferredSize(new Dimension(88, 26));
		jpViewerControlButtons.add(this.jbReset);
		
		
		// Create rewind button
		this.jbSlowDown = new JButton("<<");
		jpViewerControlButtons.add(this.jbSlowDown);
		
		
		// Create play/pause button
		this.jbPlay = new JButton("Play");
		this.jbPlay.setPreferredSize(new Dimension(70, 26));
		jpViewerControlButtons.add(this.jbPlay);
		
		
		// Create forward button
		this.jbSpeedUp = new JButton(">>");
		jpViewerControlButtons.add(this.jbSpeedUp);
		
		
		// Create statistic button
		this.jbStatistics = new JButton("Statistics");
		this.jbStatistics.setPreferredSize(new Dimension(88, 26));
		jpViewerControlButtons.add(this.jbStatistics);
	}
	
	
	/**
	 * Initializes the viewer panel with a default view
	 */
	private void init() {
		// Disable reset button
		this.jbReset.setEnabled(false);
		// Set simulation progress slider to 0
		this.jpbSimulationProgress.setValue(0);
	}
	
	
	/**
	 * Adds the listeners of the the different GUI components
	 */
	public void addViewerActionListener(ActionListener listener) {
		this.jbReset.addActionListener(listener);
		this.jbSlowDown.addActionListener(listener);
		this.jbPlay.addActionListener(listener);
		this.jbSpeedUp.addActionListener(listener);
		this.jbStatistics.addActionListener(listener);
	}


	/**
	 * Gets the simulation panel
	 * 
	 * @return The simulation panel
	 */
	public JPanel getJpSimulationPanel() {
		return this.jpSimulationPanel;
	}


	/**
	 * Gets the reset button
	 * 
	 * @return The reset button
	 */
	public JButton getJbReset() {
		return this.jbReset;
	}

	
	/**
	 * Gets the slow down button
	 * 
	 * @return The slow down button
	 */
	public JButton getJbSlowDown() {
		return this.jbSlowDown;
	}
	

	/**
	 * Gets the play button
	 * 
	 * @return The play button
	 */
	public JButton getJbPlay() {
		return this.jbPlay;
	}


	/**
	 * Gets the speed up button
	 * 
	 * @return The speed up button
	 */
	public JButton getJbSpeedUp() {
		return this.jbSpeedUp;
	}


	/**
	 * Gets the statistics button
	 * 
	 * @return The statistics button
	 */
	public JButton getJbStatistics() {
		return this.jbStatistics;
	}


	/**
	 * Gets the progress bar of the simulation 
	 * 
	 * @return The simulation progress bar
	 */
	public JProgressBar getJpbSimulationProgress() {
		return jpbSimulationProgress;
	}
	
}
